package com.fanyouzhao.ehome2.admin.controller;


import com.fanyouzhao.ehome2.admin.annotation.NeedsLog;
import com.fanyouzhao.ehome2.admin.annotation.NeedsLogin;
import com.fanyouzhao.ehome2.admin.exception.BusinessException;
import com.fanyouzhao.ehome2.admin.service.CpService;
import com.fanyouzhao.ehome2.core.pojo.Cp;
import com.fanyouzhao.ehome2.core.util.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Author: fanyouzhao
 * @Date: 11:27 2021/5/25
 */
@RestController
@RequestMapping("/cp")
@Api(value = "优惠券的管理模块",produces = "application/json;charset=UTF-8")
@NeedsLogin
@NeedsLog
public class CpController {

    @Autowired
    private CpService cpService = null;

    JsonResult jsonResult = null;

    @ApiOperation(value = "根据id查询优惠券的操作",notes="需要强调的注意事项",
            response = Map.class,httpMethod = "GET")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "id",value = "优惠券的编号",
                    required = true,dataType = "String",example = "1",type = "body")
    )
    @GetMapping("/get")
    public JsonResult get(@RequestParam("id") Integer id) throws BusinessException {
        Cp cp = cpService.selectById(id);
        if (cp!=null){
            jsonResult = new JsonResult("1","查询成功",cp);
        }else {
            throw new BusinessException("查询失败");
        }
        return jsonResult;
    }

    @ApiOperation(value = "添加优惠券的操作")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "coupon",value = "json格式的优惠券对象",dataType = "body",format = "formatBody")
    )
    @PostMapping("/add")
    public JsonResult add(Cp cp){
        System.out.println(cp);
        return null;
    }

    public JsonResult selectByPage(@RequestParam("page") Integer page,@RequestParam("size") Integer size,
                                   @RequestParam(value = "page",required = false)String name){
        return null;
    }
}
